package logic.obstacles
{

    import flash.display.*;
    import flash.geom.*;

    public class Mace extends GeneralObstacle
    {
    
        private var mace:Sprite;
        private var velocity:Number = 20;
        private var shouldUpdate:Boolean = true;
        private var particleEm:ParticleEmmiter;
        
        public function Mace(configuration:Object)
        {
            velocity = configuration.velocity;
            particleEm = new ParticleEmmiter();
            particleEm.x = -10;
            particleEm.y = 0;
            particleEm.xVelocity = 0;
            particleEm.xSpread = 10;
            particleEm.yVelocity = -4;
            particleEm.ySpread = 4;
            particleEm.beginColor = 0x000000;
            particleEm.endColor = 0x000000;
            particleEm.maxParticles = 100
            particleEm.lifetime = 14;
            particleEm.minGen = 30;
            particleEm.maxGen = 50;

            addChild(particleEm); 

        } 
    
        public override function draw():void
        {
            mace = new Sprite();
            mace.graphics.beginFill(0x000000);
            mace.graphics.lineStyle(1,0x000000)
            mace.graphics.drawCircle(0,0,5);
            for (var i:uint = 0; i<20; i++) 
            {
                mace.graphics.moveTo(0,0);
                mace.graphics.lineTo(
                    Math.sin(Math.PI * (360*Math.random()) / 180) *8,
                    Math.cos(Math.PI * (360*Math.random()) / 180) *8);
                
            }
            mace.graphics.endFill();
            
            addChild(mace);
            
           
        }
        
        private var pcLifetime = 60;
        
        public override function update():void
        {            
            if (shouldUpdate)
            {
                velocity -=0.7;
                mace.y -=velocity;

                if (mace.y>0) {
                    velocity = 20;
                    shouldUpdate = false;
                   
                    particleEm.start();
                   
                }
            } else {
                pcLifetime--;
                if (pcLifetime==0) {
                    pcLifetime = 60;
                    shouldUpdate = true;
                    particleEm.stop();
                }
            }
        }
    
    }

}
